using System;
using System.Collections.Generic;
using System.Text;
using Common.Utilities;
using Common.Utilities.Dispatcher;
using Workflows.Components.DALC;

namespace Workflows.Components
{
    [Serializable]
    public class Run
    {
        private Guid _RunID;

        public Guid RunID
        {
            get { return _RunID; }
            set { _RunID = value; }
        }

        private Guid _WorkflowID;

        public Guid WorkflowID
        {
            get { return _WorkflowID; }
            set { this._WorkflowID = value; }

        }

        private Guid _TriggerInstanceID;

        public Guid TriggerInstanceID
        {
            get { return _TriggerInstanceID; }
            set { this._TriggerInstanceID = value; }
        }

        private DateTime _SubmitTime;

        public DateTime SubmitTime
        {
            get { return _SubmitTime; }
            set { _SubmitTime = value; }
        }

        private DateTime _StartTime;

        public DateTime StartTime
        {
            get { return _StartTime; }
            set { _StartTime = value; }
        }

        private DateTime _FinishTime;

        public DateTime FinishTime
        {
            get { return _FinishTime; }
            set { _FinishTime = value; }
        }

        private List<GlobalVariable> _Vars;

        public List<GlobalVariable> Vars
        {
            get { return _Vars; }
            set { _Vars = value; }
        }

        public Run()
        {
            this._RunID = Guid.Empty;
            this._WorkflowID = Guid.Empty;
            this._TriggerInstanceID = Guid.Empty;
            this._SubmitTime = DateTime.Now;
            this._StartTime = TimeUtil.DbMinTime;
            this._FinishTime = TimeUtil.DbMaxTime;
            this._Vars = null;
        }
	
        public Run(
            Guid runID, Guid workflowID, 
            WorkflowTriggerInstance triggerInstance)
        {
            this._RunID = runID;
            this._WorkflowID = workflowID;
            this._TriggerInstanceID = triggerInstance.WorkflowTriggerInstanceID;
            this._SubmitTime = DateTime.Now;
            this._StartTime = TimeUtil.DbMinTime;
            this._FinishTime = TimeUtil.DbMaxTime;

            WorkflowDesign wfDesign = WorkflowDesignDALC.GetWorkflowDesign(workflowID);
            this._Vars=new List<GlobalVariable>();
            if(wfDesign !=null && wfDesign.GlobalVariables !=null && wfDesign.GlobalVariables.Length>0)
            {
                this._Vars.AddRange(wfDesign.GlobalVariables);
            }
        }
    }
}
